package com.cat.dataStructure03;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-ways-to-group-overlapping-ranges/description/
 * @create 2025/11/17 18:20
 * @since JDK17
 */

class Solution80 {
    public int countWays(int[][] ranges) {
        Arrays.sort(ranges, (a, b) -> a[0] - b[0]);
        int ans = 1, max = -1, n = ranges.length, N = (int)1e9 + 7;
        for (int i = 0; i < n; i++) {
            if (max < ranges[i][0]) {
                ans = ans * 2 % N;
            }
            max = Math.max(max, ranges[i][1]);
        }

        return ans;
    }
}